package com.learn.rabbitmq.quickstart;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.concurrent.TimeoutException;

/**
 * @author wangxing
 * @version 2020/8/13 22:07 Administrator
 */
public class Producter {


    public static final String QUEUE_NAME = "time";
    public static final String ROUTING_KEY = QUEUE_NAME;
    public static final String EXCHANGE = "mall.order.direct";

    public static void main(String[] args) {
        try {
//            创建连接
            Connection connection = RabbitmqUtils.getConnectionFactory().newConnection();
//            创建信道
            Channel channel = connection.createChannel();
            String message = "time is :"+ LocalDateTime.now().toString();
            //        4声明队列
//            channel.queueDeclare(QUEUE_NAME, true, false, false, null);
            channel.basicPublish(EXCHANGE, ROUTING_KEY, null, message.getBytes());
            System.out.println("发送消息:"+message);
            channel.close();
            connection.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }
    }
}
